<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="ltr">|Lorem <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">^Lorem| <span dir="rtl">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">^Lorem |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-0 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">L|orem <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">L^orem| <span dir="rtl">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">L^orem |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-1 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lo|rem <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lo^rem| <span dir="rtl">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lo^rem |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-2 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lor|em <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lor^em| <span dir="rtl">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lor^em |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-3 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lore|m <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lore^m| <span dir="rtl">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lore^m |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-4 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem| <span dir="rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem^ <span dir="rtl">ipsum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem^ |<span dir="rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 2-5 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">|ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">^ipsum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">^ipsum |dolor sit</span> amet</div>',
  `${behavior} 2-6 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">i|psum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">i^psum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">i^psum |dolor sit</span> amet</div>',
  `${behavior} 2-7 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ip|sum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ip^sum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ip^sum |dolor sit</span> amet</div>',
  `${behavior} 2-8 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ips|um dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ips^um| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ips^um |dolor sit</span> amet</div>',
  `${behavior} 2-9 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsu|m dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsu^m| dolor sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsu^m |dolor sit</span> amet</div>',
  `${behavior} 2-10 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum| dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum^ dolor| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum^ |dolor sit</span> amet</div>',
  `${behavior} 2-11 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum |dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum ^dolor| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum ^dolor |sit</span> amet</div>',
  `${behavior} 2-12 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum d|olor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum d^olor| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum d^olor |sit</span> amet</div>',
  `${behavior} 2-13 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum do|lor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum do^lor| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum do^lor |sit</span> amet</div>',
  `${behavior} 2-14 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dol|or sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dol^or| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dol^or |sit</span> amet</div>',
  `${behavior} 2-15 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolo|r sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolo^r| sit</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolo^r |sit</span> amet</div>',
  `${behavior} 2-16 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor| sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor^ sit|</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor^ |sit</span> amet</div>',
  `${behavior} 2-17 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor |sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor ^sit|</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor ^sit</span> |amet</div>',
  `${behavior} 2-18 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor s|it</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor s^it|</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor s^it</span> |amet</div>',
  `${behavior} 2-19 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor si|t</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor si^t|</span> amet</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor si^t</span> |amet</div>',
  `${behavior} 2-20 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span>| amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span>^ amet|</div>'
      : '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span>^ |amet</div>',
  `${behavior} 2-21 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> |amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> ^amet|</div>',
  `${behavior} 2-22 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> a|met</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> a^met|</div>',
  `${behavior} 2-23 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> am|et</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> am^et|</div>',
  `${behavior} 2-24 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> ame|t</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> ame^t|</div>',
  `${behavior} 2-25 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> amet|</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">Lorem <span dir="rtl">ipsum dolor sit</span> amet|</div>',
  `${behavior} 2-26 ltr right word`);
}
</script>
